package com.vn.ducktohome.screen.play;

import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.vn.ducktohome.gamelogic.GameControl;

public class StaticDuck extends Group {
	private Image duck;
	private Label number;
	private int n;
	private boolean bStray = false;

	public StaticDuck(int n, boolean bStray) {
		this.n = n;
		this.bStray = bStray;
		init();
	}

	public StaticDuck(int n) {
		super();
		this.n = n;
		init();
	}

	public void init() {

		duck = new Image(GameControl.getAtlas().findRegion("play/duck", 1));
		duck.setVisible(false);

		number = new Label("", GameControl.getMySkin());
		number.setVisible(false);

		number.setPosition(27, 3);
		if (bStray)
			number.setText(" x " + String.valueOf(this.n - 1));
		else
			number.setText(" x " + String.valueOf(this.n));

		addActor(duck);
		addActor(number);
	}

	@Override
	public void act(float delta) {
		super.act(delta);

		if (bStray) {
			if (n > 1)
				myVisible(true);
			else
				myVisible(false);
		} else {
			if (n > 0)
				myVisible(true);
			else
				myVisible(false);
		}
	}

	private void myVisible(boolean bVisible) {
		duck.setVisible(bVisible);
		number.setVisible(bVisible);
	}

	public void decrease() {
		if (n > 0) {
			n--;
			number.setText(" x " + String.valueOf(n - 1));
		}
	}

	public void increase() {
		n++;
		number.setText(" x " + String.valueOf(n));
	}

	public int getN() {
		return n;
	}
}
